﻿//gltf
function GltfService(layerInfo) {
    var GltfServicelayer = new Object;
    GltfServicelayer.id = layerInfo.hasOwnProperty("GUID") ? layerInfo.GUID : "";
    GltfServicelayer.position = layerInfo.hasOwnProperty("POSITION") ? layerInfo.POSITION : "";
    GltfServicelayer.url = layerInfo.hasOwnProperty("URL") ? layerInfo.URL.replace("http://:", "http://") : "";
    GltfServicelayer.name = layerInfo.hasOwnProperty("NAME") ? layerInfo.NAME : "";
    GltfServicelayer.servertype = layerInfo.hasOwnProperty("SERVERTYPE") ? layerInfo.SERVERTYPE : "";
    GltfServicelayer.CreateLayer = function() {
        var url = this.url.replace("http://http://", "http://");
        var thisLayer = null;
        if (this.position) {
            var positions = this.position.split(",");
            var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
                Cesium.Cartesian3.fromDegrees(parseFloat(positions[0]), parseFloat(positions[1]), positions[2] ? parseFloat(positions[2]) : 1.0)); //gltf数据加载位置
            thisLayer = viewer.scene.primitives.add(Cesium.Model.fromGltf({
                url: url,
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
                modelMatrix: modelMatrix
            }));
        } else {
            console.log("gltf模型未指定位置坐标！！！");
            thisLayer = viewer.scene.primitives.add(Cesium.Model.fromGltf({
                url: url
            }));
        }
        return thisLayer;
    }
    return GltfServicelayer;
}